package com.ctshk.rpc.train.service.impl;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONException;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.utils.TrainHttpUtils;
import com.ctshk.rpc.train.dto.*;
import com.ctshk.rpc.train.req.TrainIdPriceQueryReq;
import com.ctshk.rpc.train.req.TrainStationIdQueryReq;
import com.ctshk.rpc.train.req.TrainTicketQueryReq;
import com.ctshk.rpc.train.req.TrainTimeQueryReq;
import com.ctshk.rpc.train.service.ITrainApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;

import java.util.*;

@Slf4j
@DubboService
public class TrainApiServiceImpl implements ITrainApiService {

    @Value("${api.train.host}")
    private String host;

    @Value("${api.train.appcode}")
    private String appcode;

    @Value("${api.train.pathTrainIdTime}")
    private String pathTrainIdTime;

    @Value("${api.train.pathTrainStationIdList}")
    private String pathTrainStationIdList;

    @Value("${api.train.pathTrainStationLabel}")
    private String pathTrainStationLabel;

    @Value("${api.train.pathTrainIdPrice}")
    private String pathTrainIdPrice;

    @Value("${api.train.trainTicket}")
    private String trainTicket;


    @Override
    public Result<TrainTimeQueryDTO> getTrainIdTime(TrainTimeQueryReq req) {
        String method = "GET";
        //阿里云APPCODE
        //String appcode = appcode;
        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<>();
        //参数配置
        //日期，如：20180808
        querys.put("DATE", req.getDate());
        //抵达车站名称_英文，如：GGQ
        querys.put("END_STATION_EN", req.getEndStationEn());
        //出发车站名称_英文，如：BJP
        querys.put("START_STATION_EN", req.getStartStationEn());
        //中国铁路列车编号，如：5l000D314541
        querys.put("TRAIN_REGISTER_ID", req.getTrainRegisterId());
        try {
            HttpResponse response = TrainHttpUtils.trainDoGet(host, pathTrainIdTime, method, headers, querys);
            System.out.println("getTrainIdTime=============================================================");
            String s = response.toString();
            System.out.println("response   getTrainIdTime"+s);
            //获取response的body
            String json = EntityUtils.toString(response.getEntity());
            System.out.println("EntityUtils.toString"+json);
            System.out.println("getTrainIdTime=============================================================");
            TrainTimeQueryDTO trainTimeQueryDTO = getJsonToTrainTimeQueryDTO(json);
            return Result.success(trainTimeQueryDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.failed(SystemError.SYS_437);
    }
    /**
     * 根据json对象获取TrainTimeQueryDTO
     * @param json 数据
     * @return
     */
    public TrainTimeQueryDTO getJsonToTrainTimeQueryDTO(String json) {
        TrainTimeQueryDTO trainTimeQueryDTO = new TrainTimeQueryDTO();
        try {
            JSONObject rootObject = new JSONObject(json);
            String trainId = rootObject.get("TRAIN_ID", String.class);
            if(StringUtils.isNotBlank(trainId)){
                trainTimeQueryDTO.setTrainId(trainId);
            }
            String trainStartStationCh = rootObject.get("TRAIN_START_STATION_CH", String.class);
            if(StringUtils.isNotBlank(trainStartStationCh)){
                trainTimeQueryDTO.setTrainStartStationCh(trainStartStationCh);
            }
            String trainStartStationChEn = rootObject.get("TRAIN_START_STATION_EN", String.class);
            if(StringUtils.isNotBlank(trainStartStationChEn)) {
                trainTimeQueryDTO.setTrainEndStationEn(trainStartStationChEn);
            }
            String trainEndStationCh = rootObject.get("TRAIN_END_STATION_CH", String.class);
            if(StringUtils.isNotBlank(trainEndStationCh)) {
                trainTimeQueryDTO.setTrainEndStationCh(trainEndStationCh);
            }
            String trainEndStationEn = rootObject.get("TRAIN_END_STATION_EN", String.class);
            if(StringUtils.isNotBlank(trainEndStationEn)) {
                trainTimeQueryDTO.setTrainEndStationEn(trainEndStationEn);
            }
            String trainClassName = rootObject.get("TRAIN_CLASS_NAME", String.class);
            if(StringUtils.isNotBlank(trainClassName)) {
                trainTimeQueryDTO.setTrainClassName(trainClassName);
            }
            JSONArray entity = rootObject.getJSONArray("TRAIN_STATION_INFO_ENTITY");
            List<TrainStationInfo> infos = new ArrayList<>();
            if(null != entity){
                Iterator<Object> iterator = entity.stream().iterator();
                while (iterator.hasNext()){
                    JSONObject object = (JSONObject)iterator.next();
                    TrainStationInfo trainStationInfo = new TrainStationInfo();
                    String trainArriveTime = object.get("TRAIN_ARRIVE_TIME", String.class);
                    if(StringUtils.isNotBlank(trainArriveTime)) {
                        trainStationInfo.setTrainArriveTime(trainArriveTime);
                    }
                    String trainStartTime = object.get("TRAIN_START_TIME", String.class);
                    if(StringUtils.isNotBlank(trainStartTime)) {
                        trainStationInfo.setTrainStartTime(trainStartTime);
                    }
                    String trainStopTime = object.get("TRAIN_STOP_TIME", String.class);
                    if(StringUtils.isNotBlank(trainStopTime)) {
                        trainStationInfo.setTrainStopTime(trainStopTime);
                    }
                    String statatonOrderId = object.get("STATATON_ORDER_ID", String.class);
                    if(StringUtils.isNotBlank(statatonOrderId)) {
                        trainStationInfo.setStatatonOrderId(statatonOrderId);
                    }
                    String statatonCn = object.get("STATAION_CH", String.class);
                    if(StringUtils.isNotBlank(statatonCn)) {
                        trainStationInfo.setStatatonCn(statatonCn);
                    }
                    String statatonEn = object.get("STATAION_EN", String.class);
                    if(StringUtils.isNotBlank(statatonEn)) {
                        trainStationInfo.setStatatonEn(statatonEn);
                    }
                    String passengerTripStataionEnabled = object.get("PASSENGER_TRIP_STATAION_ENABLED", String.class);
                    if(StringUtils.isNotBlank(passengerTripStataionEnabled)) {
                        trainStationInfo.setPassengerTripStataionEnabled(passengerTripStataionEnabled);
                    }
                    infos.add(trainStationInfo);
                }
            }
            trainTimeQueryDTO.setTrainStationInfoEntity(infos);
            return trainTimeQueryDTO;
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return trainTimeQueryDTO;
    }


    @Override
    public List<TrainTimeDTO> getTrainStationIdList(TrainStationIdQueryReq req) {
        //API产品路径
        //String host = "http://itrain.market.alicloudapi.com";
        //String path = "/ai_market/ai_train/get_train_station_id_list";
        String method = "GET";
        //阿里云APPCODE
        //String appcode = "你自己的AppCode";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        //参数配置
        //日期，如：20180808
        querys.put("DATE", req.getDate());
        //抵达车站名称_英文，如：GGQ
        querys.put("END_STATION", req.getEndStationEn());
        //出发车站名称_英文，如：BJP
        querys.put("START_STATION", req.getStartStationEn());
        try {
            HttpResponse response = TrainHttpUtils.trainDoGet(host, pathTrainStationIdList, method, headers, querys);
            System.out.println("getTrainStationIdList=============================================================");
            String s = response.toString();
            System.out.println(s);
            //获取response的body
            String json = EntityUtils.toString(response.getEntity());
            System.out.println(json);
            JSONObject jsonObject = new JSONObject(json);
            JSONArray jsonArray = jsonObject.getJSONArray("火车列车车次时刻实体信息");
            List<TrainTimeDTO> list = JSONUtil.toList(jsonArray, TrainTimeDTO.class);
            System.out.println("getTrainStationIdList=============================================================");
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 根据json对象获取List<TrainTimeQueryDTO>
     * @param json 数据
     * @return
     */
    private List<TrainStationListDTO> getJsonToTrainStationListDTO(String json) {
        List<TrainStationListDTO> infos = new ArrayList<>();
        try {
            JSONArray objects = new JSONArray(json);
            if(null != objects){
                Iterator<Object> iterator = objects.stream().iterator();
                while (iterator.hasNext()){
                    JSONObject object = (JSONObject)iterator.next();
                    TrainStationListDTO trainStationListDTO = new TrainStationListDTO();
                    String trainRegisterId = object.get("TRAIN_REGISTER_ID", String.class);
                    if(StringUtils.isNotBlank(trainRegisterId)) {
                        trainStationListDTO.setTrainRegisterId(trainRegisterId);
                    }
                    String trainId = object.get("TRAIN_ID", String.class);
                    if(StringUtils.isNotBlank(trainId)) {
                        trainStationListDTO.setTrainId(trainId);
                    }
                    String trainStartStationCh = object.get("TRAIN_START_STATION_CH", String.class);
                    if(StringUtils.isNotBlank(trainStartStationCh)) {
                        trainStationListDTO.setTrainStartStationCh(trainStartStationCh);
                    }
                    String trainStartStationEn = object.get("TRAIN_START_STATION_EN", String.class);
                    if(StringUtils.isNotBlank(trainStartStationEn)) {
                        trainStationListDTO.setTrainStartStationEn(trainStartStationEn);
                    }
                    String trainEndStationCh = object.get("TRAIN_END_STATION_CH", String.class);
                    if(StringUtils.isNotBlank(trainEndStationCh)) {
                        trainStationListDTO.setTrainEndStationCh(trainEndStationCh);
                    }
                    String trainEndStationEn = object.get("TRAIN_END_STATION_EN", String.class);
                    if(StringUtils.isNotBlank(trainEndStationEn)) {
                        trainStationListDTO.setTrainEndStationEn(trainEndStationEn);
                    }
                    String trainTicketType = object.get("TRAIN_TICKET_TYPE", String.class);
                    if(StringUtils.isNotBlank(trainTicketType)) {
                        trainStationListDTO.setTrainTicketType(trainTicketType);
                    }
                    String passengerStartStationCh = object.get("PASSENGER_START_STATION_CH", String.class);
                    if(StringUtils.isNotBlank(passengerStartStationCh)) {
                        trainStationListDTO.setPassengerStartStationCh(passengerStartStationCh);
                    }
                    String passengerStartStationEn = object.get("PASSENGER_START_STATION_EN", String.class);
                    if(StringUtils.isNotBlank(passengerStartStationEn)) {
                        trainStationListDTO.setPassengerStartStationEn(passengerStartStationEn);
                    }
                    String passengerEndStationCh = object.get("PASSENGER_END_STATION_CH", String.class);
                    if(StringUtils.isNotBlank(passengerEndStationCh)) {
                        trainStationListDTO.setPassengerEndStationCh(passengerEndStationCh);
                    }
                    String passengerEndStationEn = object.get("PASSENGER_END_STATION_EN", String.class);
                    if(StringUtils.isNotBlank(passengerEndStationEn)) {
                        trainStationListDTO.setPassengerEndStationEn(passengerEndStationEn);
                    }
                    String passengerTripStartTime = object.get("PASSENGER_TRIP_START_TIME", String.class);
                    if(StringUtils.isNotBlank(passengerTripStartTime)) {
                        trainStationListDTO.setPassengerTripStartTime(passengerTripStartTime);
                    }
                    String passengerTripEndTime = object.get("PASSENGER_TRIP_END_TIME", String.class);
                    if(StringUtils.isNotBlank(passengerTripEndTime)) {
                        trainStationListDTO.setPassengerTripEndTime(passengerTripEndTime);
                    }
                    String passengerTripTime = object.get("PASSENGER_TRIP_TIME", String.class);
                    if(StringUtils.isNotBlank(passengerTripTime)) {
                        trainStationListDTO.setPassengerTripTime(passengerTripTime);
                    }
                    String passengerTripIsMorrow = object.get("PASSENGER_TRIP_IS_MORROW", String.class);
                    if(StringUtils.isNotBlank(passengerTripIsMorrow)) {
                        trainStationListDTO.setPassengerTripIsMorrow(passengerTripIsMorrow);
                    }
                    String passengerTripDate = object.get("PASSENGER_TRIP_DATE", String.class);
                    if(StringUtils.isNotBlank(passengerTripDate)) {
                        trainStationListDTO.setPassengerTripDate(passengerTripDate);
                    }
                    String passengerSoftBedSeniorBedTickets = object.get("PASSENGER_SOFT_BED_SENIOR_BED_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerSoftBedSeniorBedTickets)) {
                        trainStationListDTO.setPassengerSoftBedSeniorBedTickets(passengerSoftBedSeniorBedTickets);
                    }
                    String passengerSoftBedFirstBedTickets = object.get("PASSENGER_SOFT_BED_FIRST_BED_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerSoftBedFirstBedTickets)) {
                        trainStationListDTO.setPassengerSoftBedFirstBedTickets(passengerSoftBedFirstBedTickets);
                    }
                    String passengerNoSeatTickets = object.get("PASSENGER_NO_SEAT_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerNoSeatTickets)) {
                        trainStationListDTO.setPassengerNoSeatTickets(passengerNoSeatTickets);
                    }
                    String passengerHardBedSecondBedTickets = object.get("PASSENGER_HARD_BED_SECOND_BED_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerHardBedSecondBedTickets)) {
                        trainStationListDTO.setPassengerHardBedSecondBedTickets(passengerHardBedSecondBedTickets);
                    }
                    String passengerHardSeatTickets = object.get("PASSENGER_HARD_SEAT_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerHardSeatTickets)) {
                        trainStationListDTO.setPassengerHardSeatTickets(passengerHardSeatTickets);
                    }
                    String passengerSecondSeatTickets = object.get("PASSENGER_SECOND_SEAT_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerSecondSeatTickets)) {
                        trainStationListDTO.setPassengerSecondSeatTickets(passengerSecondSeatTickets);
                    }
                    String passengerFirstSeatTickets = object.get("PASSENGER_FIRST_SEAT_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerFirstSeatTickets)) {
                        trainStationListDTO.setPassengerFirstSeatTickets(passengerFirstSeatTickets);
                    }
                    String passengerBusinessSeatTickets = object.get("PASSENGER_BUSINESS_SEAT_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerBusinessSeatTickets)) {
                        trainStationListDTO.setPassengerBusinessSeatTickets(passengerBusinessSeatTickets);
                    }
                    String passengerChinaBedTickets = object.get("PASSENGER_CHINA_BED_TICKETS", String.class);
                    if(StringUtils.isNotBlank(passengerChinaBedTickets)) {
                        trainStationListDTO.setPassengerChinaBedTickets(passengerChinaBedTickets);
                    }
                    infos.add(trainStationListDTO);
                }
            }
            return infos;
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return infos;


    }

    @Override
    public List<TrainStationLabelDTO> getTrainStationLabel() {
        String method = "GET";
        //阿里云APPCODE
        //String appcode = "你自己的AppCode";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        try {
            HttpResponse response = TrainHttpUtils.trainDoGet(host, pathTrainStationLabel, method, headers, querys);
            System.out.println("getTrainStationLabel=============================================================");
            String s = response.toString();
            System.out.println(s);
            //获取response的body
            String json = EntityUtils.toString(response.getEntity());
            System.out.println(json);
            List<TrainStationLabelDTO> list = getJsonToTrainStationLabelDTO(json);
            System.out.println("getTrainStationLabel=============================================================");
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 根据json对象获取List<TrainStationLabelDTO>
     * @param json 数据
     * @return
     */
    private List<TrainStationLabelDTO> getJsonToTrainStationLabelDTO(String json) {
        List<TrainStationLabelDTO> infos = new ArrayList<>();
        try {
            JSONArray objects = new JSONArray(json);
            if(null != objects){
                Iterator<Object> iterator = objects.stream().iterator();
                while (iterator.hasNext()){
                    JSONObject object = (JSONObject)iterator.next();
                    TrainStationLabelDTO trainStationLabelDTO = new TrainStationLabelDTO();
                    String stationCh = object.get("STATION_CH", String.class);
                    if(StringUtils.isNotBlank(stationCh)) {
                        trainStationLabelDTO.setStationCh(stationCh);
                    }
                    String stationEn = object.get("STATION_EN", String.class);
                    if(StringUtils.isNotBlank(stationEn)) {
                        trainStationLabelDTO.setStationEn(stationEn);
                    }
                    infos.add(trainStationLabelDTO);
                }
            }
            return infos;
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return infos;



    }

    @Override
    public TrainIdPriceDTO getTrainIdPrice(TrainIdPriceQueryReq req) {
        //API产品路径
        //String host = "http://itrain.market.alicloudapi.com";
        //String path = "/ai_market/ai_train/get_train_id_price";
        String method = "GET";
        //阿里云APPCODE
        //String appcode = "你自己的AppCode";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        //参数配置
        //日期，如：20180808
        querys.put("DATE", req.getDate());
        //旅客抵达车站序号，如： 02
        querys.put("END_STATATON_ORDER_ID", req.getEndStatatonOrderId());
        //旅客出发车站序号，如： 02
        querys.put("START_STATATON_ORDER_ID", req.getStartStatatonOrderId());
        //中国铁路列车编号，如：5l000D314541
        querys.put("TRAIN_REGISTER_ID", req.getTrainRegisterId());
        //车次车票类型，如：OMO
        querys.put("TRAIN_TICKET_TYPE", req.getTrainTicketType());
        try {
            HttpResponse response = TrainHttpUtils.trainDoGet(host, pathTrainIdPrice, method, headers, querys);
            System.out.println("getTrainIdPrice=============================================================");
            String s = response.toString();
            System.out.println(s);
            //获取response的body
            String json = EntityUtils.toString(response.getEntity());
            System.out.println(json);
            TrainIdPriceDTO trainIdPriceDTO = getJsonToTrainIdPriceDTO(json);
            System.out.println("getTrainIdPrice=============================================================");
            return trainIdPriceDTO;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<ApiTrainProductDTO> getTrainTicketList(TrainTicketQueryReq req) {
        //API产品路径
        //String host = "http://itrain.market.alicloudapi.com";
        //String path = "/ai_market/ai_train/get_train_station_id_list";
        String method = "GET";
        //阿里云APPCODE
        //String appcode = "你自己的AppCode";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        //参数配置
        //日期，如：20180808
        querys.put("date", req.getDate());
        //抵达车站名称_英文，如：GGQ
        querys.put("end", req.getEnd());
        //出发车站名称_英文，如：BJP
        querys.put("start", req.getStart());
        try {
            HttpResponse response = TrainHttpUtils.trainDoGet(host, trainTicket, method, headers, querys);
            log.info("【获取api火车票列表】"+response.toString());
            //System.out.println("getTrainTicketList=============================================================");
            //String s = response.toString();
            //System.out.println(s);
            //获取response的body
            String json = EntityUtils.toString(response.getEntity());
            System.out.println(json);
            JSONObject jsonObject = new JSONObject(json);
            if (!jsonObject.containsKey("result")) {
                return new ArrayList<>();
            }
            JSONObject result = jsonObject.getJSONObject("result");
            JSONArray list = result.getJSONArray("list");
            log.info("【获取api火车票列表结束】");
            //System.out.println("getTrainTicketList=============================================================");
            return JSONUtil.toList(list, ApiTrainProductDTO.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private TrainIdPriceDTO getJsonToTrainIdPriceDTO(String json) {
        TrainIdPriceDTO trainIdPriceDTO = new TrainIdPriceDTO();
        try {
            JSONObject rootObject = new JSONObject(json);
            String trainRegisterId = rootObject.get("TRAIN_REGISTER_ID", String.class);
            if(StringUtils.isNotBlank(trainRegisterId)){
                trainIdPriceDTO.setTrainRegisterId(trainRegisterId);
            }
            String passengerSoftBedSeniorBedTicketsPrice = rootObject.get("PASSENGER_SOFT_BED_SENIOR_BED_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerSoftBedSeniorBedTicketsPrice)){
                trainIdPriceDTO.setPassengerSoftBedSeniorBedTicketsPrice(passengerSoftBedSeniorBedTicketsPrice);
            }
            String passengerSoftBedFirstBedTicketsPrice = rootObject.get("PASSENGER_SOFT_BED_FIRST_BED_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerSoftBedFirstBedTicketsPrice)) {
                trainIdPriceDTO.setPassengerSoftBedFirstBedTicketsPrice(passengerSoftBedFirstBedTicketsPrice);
            }
            String passengerNoSeatTicketsPrice = rootObject.get("PASSENGER_NO_SEAT_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerNoSeatTicketsPrice)) {
                trainIdPriceDTO.setPassengerNoSeatTicketsPrice(passengerNoSeatTicketsPrice);
            }
            String passengerHardBedSecondBedTicketsPrice = rootObject.get("PASSENGER_HARD_BED_SECOND_BED_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerHardBedSecondBedTicketsPrice)) {
                trainIdPriceDTO.setPassengerHardBedSecondBedTicketsPrice(passengerHardBedSecondBedTicketsPrice);
            }
            String passengerHardSeatTicketsPrice = rootObject.get("PASSENGER_HARD_SEAT_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerHardSeatTicketsPrice)) {
                trainIdPriceDTO.setPassengerHardSeatTicketsPrice(passengerHardSeatTicketsPrice);
            }
            String passengerSoftSeatTicketsPrice = rootObject.get("PASSENGER_SOFT_SEAT_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerSoftSeatTicketsPrice)) {
                trainIdPriceDTO.setPassengerSoftSeatTicketsPrice(passengerSoftSeatTicketsPrice);
            }
            String passengerSecondSeatTicketsPrice = rootObject.get("PASSENGER_SECOND_SEAT_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerSecondSeatTicketsPrice)) {
                trainIdPriceDTO.setPassengerSecondSeatTicketsPrice(passengerSecondSeatTicketsPrice);
            }
            String passengerFirstSeatTicketsPrice = rootObject.get("PASSENGER_FIRST_SEAT_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerFirstSeatTicketsPrice)) {
                trainIdPriceDTO.setPassengerFirstSeatTicketsPrice(passengerFirstSeatTicketsPrice);
            }
            String passengerBusinessSeatTicketsPrice = rootObject.get("PASSENGER_BUSINESS_SEAT_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerBusinessSeatTicketsPrice)) {
                trainIdPriceDTO.setPassengerBusinessSeatTicketsPrice(passengerBusinessSeatTicketsPrice);
            }
            String passengerChinaBedTicketsPrice = rootObject.get("PASSENGER_CHINA_BED_TICKETS_PRICE", String.class);
            if(StringUtils.isNotBlank(passengerChinaBedTicketsPrice)) {
                trainIdPriceDTO.setPassengerChinaBedTicketsPrice(passengerChinaBedTicketsPrice);
            }
            return trainIdPriceDTO;
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }


}
